home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 009 (1987-02-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 009 (1987-02-15)(Ossowski, Stefan)(DE)(PD).adf / HackIconII_Source / SetColors.c < prev    next >
C/C++ Source or Header  |  1987-03-04  |  10KB  |  310 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  2. * |_o_o|\\ Copyright (c) 1987 The Software Distillery.  All Rights Reserved *
  3. * |. o.| ||          Written by Doug Walker                                 *
  4. * | .  | ||          The Software Distillery                                *
  5. * | o  | ||          235 Trillingham Lane                                   *
  6. * |  . |//           Cary, NC 27511                                         *
  7. * ======             BBS:(919)-471-6436                                     *
  8. \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  9.  
  10. #include "mydebug.h"
  11.  
  12. #include "exec/types.h"
  13. #include "exec/memory.h"
  14. #include "intuition/intuition.h"
  15. #include "graphics/gfxbase.h"
  16. #include "stdio.h"
  17.  
  18. #include "hackicon.h"
  19.  
  20. extern struct Menu Titles[], ORCTitles[], ColorTitles[];
  21. extern struct Border Borders[];
  22.  
  23. extern struct Screen   *Screen;
  24. extern struct Window   *Window;
  25. extern struct ViewPort *ViewPort;
  26.  
  27. extern struct IntuiText MiscText[];
  28.  
  29. extern struct PropInfo r_prop, g_prop, b_prop;
  30. extern struct Gadget red_gad, blue_gad, green_gad;
  31.  
  32. extern USHORT colormap[];
  33.  
  34. static USHORT tmpmap[16];
  35. extern int hires;
  36.  
  37. extern struct iconfont *fonts[];
  38. extern int fontnum;
  39.  
  40. void PickColor(cnum, PalWindow, curcol)
  41. int cnum, curcol;
  42. struct Window *PalWindow;
  43. {
  44.  
  45. /*
  46.  * SetAPen(calling_window->RPort,cursel);
  47.  * RectFill(calling_window->RPort,PLXLEFT+133,  PLYTOP+3,
  48.  *                                PLXLEFT+PLWIDTH-5,PLYTOP+16);
  49.  */
  50.  
  51.    r_prop.HorizPot = (tmpmap[cnum] & 0xf00) << 4;
  52.    g_prop.HorizPot = (tmpmap[cnum] & 0x0f0) << 8;
  53.    b_prop.HorizPot = tmpmap[cnum] << 12;
  54.  
  55.    Borders[2].FrontPen = 0;
  56.    DrawBorder(PalWindow->RPort, &Borders[2], 
  57.               (curcol<16 ? 0 : PLXWIDTH+2),
  58.               (curcol%16)*PLYHEIGHT);
  59.  
  60.    RefreshGadgets(&red_gad, PalWindow, NULL);
  61.  
  62.    Borders[2].FrontPen = 1;
  63.    DrawBorder(PalWindow->RPort, &Borders[2], 
  64.               (cnum<16 ? 0 : PLXWIDTH+2),
  65.               (cnum%16)*PLYHEIGHT);
  66. }
  67.  
  68. SetColors()
  69. {
  70.    struct NewWindow *NewWindow;
  71.    struct Window *PalWindow;
  72.    struct ViewPort *PalVP;
  73.    struct IntuiMessage *imsg;
  74.    struct Gadget *Gadget;
  75.    int flag, i;
  76.  
  77.    USHORT Code, curcolor, partial;
  78.    ULONG Class;
  79.  
  80.    BUG(1, ("SetColors: Enter\n"))
  81.    
  82.    r_prop.Flags = g_prop.Flags = b_prop.Flags = FREEHORIZ | AUTOKNOB;
  83.    r_prop.HorizBody = g_prop.HorizBody = b_prop.HorizBody = 0x1000;
  84.  
  85.    curcolor = 0;
  86.    movmem((char *)colormap, (char *)tmpmap, 16*sizeof(USHORT));
  87.  
  88.    /* Disable Menus */
  89.    ClearMenuStrip(Window);
  90.  
  91.    if(!(NewWindow = (struct NewWindow *)
  92.             AllocMem(sizeof(struct NewWindow), MEMF_CHIP | MEMF_CLEAR))
  93.      )
  94.    {
  95.       AutoRequest(Window, &MiscText[3], NULL, &MiscText[2], 0, 0, 410, 90);
  96.       return(1);
  97.    }
  98.  
  99.    NewWindow->LeftEdge = SWIDTH/4;
  100.    NewWindow->TopEdge = SHEIGHT/4;
  101.    NewWindow->Width  = CESWIDTH + PLXWIDTH+4;
  102.    NewWindow->Height = CESHEIGHT;
  103.    NewWindow->DetailPen = 1;
  104.    NewWindow->BlockPen  = 2;
  105.    NewWindow->IDCMPFlags  = (GADGETUP | GADGETDOWN | MOUSEMOVE | MENUPICK);
  106.    NewWindow->Flags = (SMART_REFRESH | ACTIVATE | WINDOWDRAG);
  107.    NewWindow->Title = (UBYTE *) "Palette Window";
  108.    NewWindow->Screen = Screen;
  109.    NewWindow->MinWidth  =
  110.    NewWindow->MaxWidth  = SWIDTH/2;
  111.    NewWindow->MinHeight =
  112.    NewWindow->MaxHeight = SHEIGHT/2;
  113.    NewWindow->Type = CUSTOMSCREEN;
  114.    NewWindow->FirstGadget = &red_gad;
  115.  
  116.    PalWindow = (struct Window *)OpenWindow(NewWindow);
  117. BUG(9, ("SetColors: Window open\n"))
  118.  
  119.    DrawBorder(PalWindow->RPort, &Borders[1], 0, 0);
  120.    if(hires) DrawBorder(PalWindow->RPort, &Borders[1], PLXWIDTH+3, 0);
  121.    PickColor(0, PalWindow, 0);
  122.    ORCTitles[0].NextMenu = ColorTitles;
  123.    SetMenuStrip(PalWindow, ORCTitles);
  124.  
  125.    FreeMem(NewWindow, sizeof(struct NewWindow));
  126. BUG(9, ("SetColors: newwindow mem freed\n"))
  127.  
  128.    PalVP= (struct ViewPort *) ViewPortAddress(PalWindow);
  129.    LoadRGB4(PalVP, tmpmap, 16);
  130.    
  131.    for(flag=1; flag; )
  132.    {
  133.       if(!(imsg = (struct IntuiMessage *)GetMsg(PalWindow->UserPort)))
  134.       {
  135.          WaitPort(PalWindow->UserPort);
  136.          continue;
  137.       }
  138. DOMSG:
  139. BUG(4, ("SetColors: at DOMSG, Class=%d\n", imsg->Class))
  140.       Class  = imsg->Class;
  141.       Code   = imsg->Code;
  142.       Gadget = (struct Gadget *)imsg->IAddress;
  143.       ReplyMsg(imsg);
  144.  
  145.       switch(Class)
  146.       {
  147.          case GADGETDOWN:
  148.          case MOUSEMOVE:
  149.             BUG(1, ("SetColors: Case GADGETDOWN\n"))
  150.             if(Gadget->GadgetID > 15)
  151.             {
  152.                BUG(1, ("SetColors: [RGB] gadget\n"))
  153.                if(Gadget->GadgetID == G_RED)
  154.                {
  155.                   partial = ((g_prop.HorizPot >> 8) & 0xf0) + 
  156.                             (b_prop.HorizPot  >>12);
  157.                   while(1)
  158.                   {
  159.                      if(imsg=(struct IntuiMessage *)
  160.                                  GetMsg(PalWindow->UserPort))
  161.                      {
  162.                         tmpmap[curcolor]=((r_prop.HorizPot>>4) & 0xf00) + partial;
  163.                         LoadRGB4(PalVP, tmpmap, 16);
  164.                         if(imsg->Class != MOUSEMOVE) goto DOMSG;
  165.                         ReplyMsg(imsg);
  166.                      }
  167.                      else
  168.                         WaitPort(PalWindow->UserPort);
  169.                   }
  170.                }
  171.                else if(Gadget->GadgetID == G_GREEN)
  172.                {
  173.                   partial = ((r_prop.HorizPot >> 4) & 0xf00) + 
  174.                             (b_prop.HorizPot  >>12);
  175.                   while(1)
  176.                   {
  177.                      if(imsg=(struct IntuiMessage *)
  178.                                  GetMsg(PalWindow->UserPort))
  179.                      {
  180.                         tmpmap[curcolor]=((g_prop.HorizPot>>8) & 0xf0) + partial;
  181.                         LoadRGB4(PalVP, tmpmap, 16);
  182.                         if(imsg->Class != MOUSEMOVE) goto DOMSG;
  183.                         ReplyMsg(imsg);
  184.                      }
  185.                      else
  186.                         WaitPort(PalWindow->UserPort);
  187.                   }
  188.                }
  189.                else
  190.                {
  191.                   partial = ((r_prop.HorizPot >> 4) & 0xf00) + 
  192.                             ((g_prop.HorizPot >> 8) & 0xf0);
  193.                   while(1)
  194.                   {
  195.                      if(imsg=(struct IntuiMessage *)
  196.                                  GetMsg(PalWindow->UserPort))
  197.                      {
  198.                         tmpmap[curcolor] = (b_prop.HorizPot >> 12) + partial;
  199.                         LoadRGB4(PalVP, tmpmap, 16);
  200.                         if(imsg->Class != MOUSEMOVE) goto DOMSG;
  201.                         ReplyMsg(imsg);
  202.                      }
  203.                      if(!imsg) WaitPort(PalWindow->UserPort);
  204.                   }
  205.                }
  206.             }
  207.             BUG(1, ("SetColors: End case GADGETDOWN\n"))
  208.             break;
  209.  
  210.          case GADGETUP:
  211.             BUG(1, ("SetColors: Case GADGETUP\n"))
  212.             switch(Gadget->GadgetID)
  213.             {
  214.                case G_RED:
  215.                case G_GREEN:
  216.                case G_BLUE:
  217.                   BUG(1, ("SetColors: Case RED, GREEN or BLUE\n"))
  218.                   break;
  219.                   
  220.                default:
  221.                   /* Must be a color selection gadget */
  222.                   PickColor(Gadget->GadgetID, PalWindow, curcolor);
  223.                   curcolor = Gadget->GadgetID;
  224.                   BUG(5, ("SetColors: Color gadget # %d\n", curcolor))
  225.                   break;
  226.             }
  227.  
  228.             break;
  229.             
  230.          case MENUPICK:
  231.             if(Code == MENUNULL) break;
  232.  
  233.             BUG(8, ("SetColors: itemnum = %d, subnum=%d\n", ITEMNUM(Code), SUBNUM(Code)))
  234.  
  235.             if(!MENUNUM(Code))
  236.             {
  237.                switch(ITEMNUM(Code))
  238.                {
  239.                   case ME_SAVE:
  240.                      BUG(1, ("SetColors: Case OK\n"))
  241.                      flag = 0;
  242.                      movmem((char *)tmpmap, (char *)colormap, 16*sizeof(USHORT));
  243.                      break;
  244.                   
  245.                   case ME_QUIT:
  246.                      BUG(1, ("SetColors: Case CANCEL\n"))
  247.                      LoadRGB4(PalVP, colormap, 16);
  248.                      flag = 0;
  249.                      break;
  250.                   
  251.                   case ME_RESET:
  252.                      BUG(1, ("SetColors: Case RESET\n"))
  253.                      movmem((char *)colormap, (char *)tmpmap, 16*sizeof(USHORT));
  254.                      LoadRGB4(PalVP, tmpmap, 16);
  255.                      PickColor(curcolor, PalWindow, curcolor);
  256.                      break;
  257.                   
  258.                }
  259.             }
  260.             else
  261.             {
  262.                switch(ITEMNUM(Code))
  263.                {
  264.                   case MC_ORGCOL:
  265.                      movmem((char *)fonts[fontnum]->colormap, 
  266.                             (char *)tmpmap,16*sizeof(USHORT));
  267.                      LoadRGB4(PalVP, tmpmap, 16);
  268.                      break;
  269.  
  270.                   case MC_ALTCOL:
  271.                      i = fontnum;
  272.                      do
  273.                      {
  274.                         i = (i+1)%MAXFONTS;
  275.                         if(fonts[i]) break;
  276.                      }
  277.                      while(i != fontnum);
  278.                      if(i == fontnum)
  279.                         DisplayBeep(NULL);
  280.                      else
  281.                      {
  282.                         movmem((char *)fonts[i]->colormap, 
  283.                                (char *)tmpmap,16*sizeof(USHORT));
  284.                         LoadRGB4(PalVP, tmpmap, 16);
  285.                         PickColor(curcolor, PalWindow, curcolor);
  286.                      }
  287.                      break;                     
  288.                }
  289.             }
  290.             break;
  291.             
  292.          default:
  293.             BUG(1, ("SetColors: Unknown Class = %d\n", Class))
  294.             break;
  295.       }
  296.    }
  297.  
  298.    while(imsg = (struct IntuiMessage *)GetMsg(Window->UserPort)) 
  299.       ReplyMsg(imsg);
  300.  
  301.    ClearMenuStrip(PalWindow);
  302.    CloseWindow(PalWindow);
  303.    
  304.    SetMenuStrip(Window, Titles);
  305.    
  306.    BUG(1, ("SetColors: Exit\n"))
  307.    return(0);
  308. }
  309.  
  310.